class SampleScrollRect extends egret.DisplayObjectContainer {
    private circle: egret.Shape
    private slider: egret.Shape
    private touchX: number
    private touchY: number

    public constructor() {
        super()
        this.once(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(): void {
        console.log("onAddToStage")
        this.circle = new egret.Shape()
        this.circle.graphics.beginFill(0xFFCC00)
        this.circle.graphics.drawCircle(200, 200, 200)
        this.circle.scrollRect = new egret.Rectangle(0, 0, 200, 200)
        this.addChild(this.circle)

        this.slider = new egret.Shape()
        this.slider.graphics.beginFill(0xff0000)
        this.slider.graphics.drawRect(0, 0, 10, 30)
        this.slider.graphics.endFill()
        this.slider.touchEnabled = true
        this.addChild(this.slider)
        this.slider.x = 300

        this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.trackTouch, this)
        this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.trackTouch, this)
        this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.trackTouch, this)

        this.slider.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._begin, this)
        this.slider.addEventListener(egret.TouchEvent.TOUCH_END, this._end, this)
    }

    private _begin(evt: egret.TouchEvent): void {
        console.log("_begin")
        this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this._move, this)
        this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this._end, this)
    }

    private _end(evt: egret.TouchEvent): void {
        console.log("_end")
        this.stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this._move, this)
        this.stage.removeEventListener(egret.TouchEvent.TOUCH_END, this._end, this)
    }

    private _move(evt: egret.TouchEvent): void {
        console.log("_move")
        var rect: egret.Rectangle = this.circle.scrollRect
        console.log(this.touchY)
        rect.y = this.touchY
        this.slider.y = this.touchY
        console.log(rect)
        this.circle.scrollRect = rect
    }

    private trackTouch(evt:egret.TouchEvent) {
        console.log("trackTouch")
        this.touchX = evt.stageX
        this.touchY = evt.stageY
    }
}